package org.rsbot.script;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import org.rsbot.bot.Bot;
import org.rsbot.script.wrappers.RSTile;

public class PaintTools {
    
    Methods methods;
    
    public PaintTools(final Bot bot) {
        this.methods = bot.methods;
    }
    
    
	public String msToReadableTime(long msTime, final boolean includeDays) {
		final long days = msTime / 1000 / 3600 / 24;
		if (includeDays) {
			msTime -= days * 24 * 3600 * 1000;
		}
		final long hrs = msTime / 1000 / 3600;
		msTime -= hrs * 3600 * 1000;
		final long mins = msTime / 1000 / 60;
		msTime -= mins * 60 * 1000;
		final long secs = msTime / 1000;
		if (includeDays)
			return String.format("%1$02d:%2$02d:%3$02d:%4$02d", days, hrs, mins, secs);
		return String.format("%1$02d:%2$02d:%3$02d", hrs, mins, secs);
	}

	public void highlightTile(final Graphics g, final RSTile t,
			final Color outline, final Color fill, final String text) {
		if (t == null)
			return;

		final Point pn = methods.calc.tileToScreen(t.getX(), t.getY(), 0, 0, 0);
		final Point px = methods.calc.tileToScreen(t.getX() + 1, t.getY(), 0,
				0, 0);
		final Point py = methods.calc.tileToScreen(t.getX(), t.getY() + 1, 0,
				0, 0);
		final Point pxy = methods.calc.tileToScreen(t.getX() + 1, t.getY() + 1,
				0, 0, 0);
		if (py.x == -1 || pxy.x == -1 || px.x == -1 || pn.x == -1)
            return;
		g.setColor(outline);
		g.drawPolygon(new int[] { py.x, pxy.x, px.x, pn.x }, new int[] { py.y,
				pxy.y, px.y, pn.y }, 4);
		g.setColor(fill);
		g.fillPolygon(new int[] { py.x, pxy.x, px.x, pn.x }, new int[] { py.y,
				pxy.y, px.y, pn.y }, 4);
		
		g.setColor(Color.white);
		g.drawString(text, py.x-15, pxy.y-15);
	}
    public void highlightTile(final Graphics g, final RSTile t, final Color outline, final String text) {
    	final Color fill = new Color(outline.getRed(), outline.getGreen(), outline.getBlue(), 50);
    	highlightTile(g, t, outline, fill, text);
    }
    public void highlightTile(final Graphics g, final RSTile t, final Color outline) {
    	highlightTile(g, t, outline, "");
    }
	
}
